package com.clf.tms.listener;

import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyElasticJobListener implements ElasticJobListener {

    private long beginTime = 0;

    @Override
    public void beforeJobExecuted(ShardingContexts shardingContexts) {
        if (shardingContexts.getShardingItemParameters().size() > 0) {
            beginTime = System.currentTimeMillis();
            log.info("===>{} JOB BEGIN TIME: {} <===", shardingContexts.getJobName(), beginTime);
        }

    }

    @Override
    public void afterJobExecuted(ShardingContexts shardingContexts) {
        if (shardingContexts.getShardingItemParameters().size() > 0) {
            long endTime = System.currentTimeMillis();
            log.info("===>{} JOB END TIME: {},TOTAL CAST: {} <===", shardingContexts.getJobName(), endTime, endTime - beginTime);
        }
    }

}
